<?php

class Application_Model_Product {
	
	protected $id;
	protected $id_category;
	protected $name;
	protected $picture_location;
	protected $price;
	protected $nbr_pieces; 
	
	public function __construct(array $options = null){
		if (is_array($options)) {
			$this->setOptions($options);
		}
	}
	
	public function __set($name, $value){
		$method = 'set' . $name;
		if (('mapper' == $name) || !method_exists($this, $method)) {
			throw new Exception('Invalid product property');
		}
		$this->$method($value);
	}
	
	public function __get($name){
		$method = 'get' . $name;
		if (('mapper' == $name) || !method_exists($this, $method)) {
			throw new Exception('Invalid product property');
		}
		return $this->$method();
	}
	
	public function setOptions(array $options){
		$methods = get_class_methods($this);
		foreach ($options as $key => $value) {
			$method = 'set' . ucfirst($key);
			if (in_array($method, $methods)) {
				$this->$method($value);
			}
		}
		return $this;
	}
	
	public function setId($id){
		$this->id = (int) $id;
		return $this;
	}
	
	public function getId(){
		return $this->id;
	}
	
	public function setId_category($id){
		$this->id_category = (int) $id;
		return $this;
	}
	
	public function getId_category(){
		return $this->id_category;
	}
		
	public function setName($name){
		$this->name = (string) $name;
		return $this;
	}
	
	public function getName(){
		return $this->name;
	}
	
	public function setPicture_location($location){
		$this->picture_location = (string) $location;
		return $this;
	}
	
	public function getPicture_location(){
		return $this->picture_location;
	}
	
	public function setPrice($price){
		$this->price = (double) $price;
		return $this;
	}
	
	public function getPrice(){
		return $this->price;
	}
	
	public function setNbr_pieces($nbr){
		$this->nbr_pieces = (int) $nbr;
		return $this;
	}
	
	public function getNbr_pieces(){
		return $this->nbr_pieces;
	}
}

